package com.point.business.servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.point.business.database.managers.UsersManager;
import com.point.business.database.model.History;
import com.point.business.util.UTFUtil;

/**
 * Servlet implementation class LoginServlet
 */

public class UsersHistory extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public UsersHistory() {
		super();
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("application/json");
		UTFUtil.utf8(request, response);
        PrintWriter out = response.getWriter();
        int id = Integer.parseInt(request.getParameter("id"));
		List<History> history = UsersManager.getInstance().getUserHistory(id);
		Gson gson = new GsonBuilder().setPrettyPrinting().create();
		String json = gson.toJson(history);
		out.print(json);
	}
}
